const puppeteer = require('puppeteer');
// https://blog.csdn.net/mengxiangxingdong/article/details/99237204
// https://zhaoqize.github.io/puppeteer-api-zh_CN/#/
(async () => {

    //模拟淘宝联盟创建推广位

    const browser = await puppeteer.launch({
        args: [
            '--disable-web-security'
        ],
        headless: false,
        ignoreHTTPSErrors: true,
        defaultViewport: null,
        timeout: 10000,
        devtools: true,
        slowMo: 250,
        executablePath: 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe'
    });
    try {
        const page = await browser.newPage();
        await page.setViewport({width: 1920, height: 1080});
        await page.setJavaScriptEnabled(true);
        await page.goto('https://www.dataoke.com/shouquan?key_type=1&type=1');

        await page.waitForNavigation({timeout: 200000000})  //等待网页操作
        await page.goto('https://www.dataoke.com/shouquan?key_type=1&type=1');
        await page.mainFrame().addScriptTag({
            url: 'https://cdn.bootcss.com/jquery/3.2.0/jquery.min.js'
        })
        await page.waitForSelector('.dtk-pages-auth-center-auth-tb-style-tit');
        // await page.waitForTimeout(1000)


        console.log("大淘客淘宝授权中心")

        for (let p of pidArray) {
            console.log("当前创建。" + p.name)
            await page.evaluate(x => {
                if ($(".ant-modal").length) {
                    $(".ant-modal-footer .ant-btn:eq(0)").click();
                }
                $('.dtk-pages-auth-center-auth-tb-style-tit p:eq(0)').click()
            });
            await page.waitForSelector("#tbAuth_pid");
            await page.type("#tbAuth_pid", p.pid, {delay: 10}) //输入
            await page.type("#tbAuth_remark", p.name, {delay: 10}) //输入
            await page.waitForTimeout(200)
            await page.click('.ant-modal-footer .ant-btn-primary')  //确定
            await page.waitForTimeout(1000)
        }

        console.log('结束了')
        await page.close();

    } catch (e) {
        throw e
    } finally {
        await browser.close();
    }
})();

var pidArray = [{'pid': 'mm_59461769_1953900113_110777450362', 'name': '券小九网站2'},
    {'pid': 'mm_59461769_1953900113_110775700402', 'name': '券小九网站3'},
    {'pid': 'mm_59461769_1953900113_110769600449', 'name': '券小九网站4'},
    {'pid': 'mm_59461769_1953900113_110789250298', 'name': '券小九网站5'},
    {'pid': 'mm_59461769_1953900113_110789300259', 'name': '券小九网站6'},
    {'pid': 'mm_59461769_1953900113_110790750256', 'name': '券小九网站7'},
    {'pid': 'mm_59461769_1953900113_110793700244', 'name': '券小九网站8'},
    {'pid': 'mm_59461769_1953900113_110792900252', 'name': '券小九网站9'},
    {'pid': 'mm_59461769_1953900113_110786900322', 'name': '券小九网站10'},
    {'pid': 'mm_59461769_1953900113_110812800309', 'name': '券小九网站11'},
    {'pid': 'mm_59461769_1953900113_110818400183', 'name': '券小九网站12'},
    {'pid': 'mm_59461769_1953900113_110816650217', 'name': '券小九网站13'},
    {'pid': 'mm_59461769_1953900113_110818750198', 'name': '券小九网站14'},
    {'pid': 'mm_59461769_1953900113_110817850191', 'name': '券小九网站15'},
    {'pid': 'mm_59461769_1953900113_110815600204', 'name': '券小九网站16'},
    {'pid': 'mm_59461769_1953900113_110817300177', 'name': '券小九网站17'},
    {'pid': 'mm_59461769_1953900113_110820900127', 'name': '券小九网站18'},
    {'pid': 'mm_59461769_1953900113_110820800135', 'name': '券小九网站19'},
    {'pid': 'mm_59461769_1953900113_110816850199', 'name': '券小九网站20'},
    {'pid': 'mm_59461769_1953900113_110820750119', 'name': '券小九网站21'},
    {'pid': 'mm_59461769_1953900113_110814200271', 'name': '券小九网站22'},
    {'pid': 'mm_59461769_1953900113_110815750227', 'name': '券小九网站23'},
    {'pid': 'mm_59461769_1953900113_110814800272', 'name': '券小九网站24'},
    {'pid': 'mm_59461769_1953900113_110813700286', 'name': '券小九网站25'},
    {'pid': 'mm_59461769_1953900113_110813100299', 'name': '券小九网站26'},
    {'pid': 'mm_59461769_1953900113_110819850163', 'name': '券小九网站27'},
    {'pid': 'mm_59461769_1953900113_110813300293', 'name': '券小九网站28'},
    {'pid': 'mm_59461769_1953900113_110818750199', 'name': '券小九网站29'},
    {'pid': 'mm_59461769_1953900113_110813300294', 'name': '券小九网站30'},
    {'pid': 'mm_59461769_1953900113_110816900214', 'name': '券小九网站31'},
    {'pid': 'mm_59461769_1953900113_110820650144', 'name': '券小九网站32'},
    {'pid': 'mm_59461769_1953900113_110819400178', 'name': '券小九网站33'},
    {'pid': 'mm_59461769_1953900113_110817750205', 'name': '券小九网站34'},
    {'pid': 'mm_59461769_1953900113_110819850164', 'name': '券小九网站35'},
    {'pid': 'mm_59461769_1953900113_110815900236', 'name': '券小九网站36'},
    {'pid': 'mm_59461769_1953900113_110814400250', 'name': '券小九网站37'},
    {'pid': 'mm_59461769_1953900113_110815200244', 'name': '券小九网站38'},
    {'pid': 'mm_59461769_1953900113_110814100261', 'name': '券小九网站39'},
    {'pid': 'mm_59461769_1953900113_110817350198', 'name': '券小九网站40'},
    {'pid': 'mm_59461769_1953900113_110819750181', 'name': '券小九网站41'},
    {'pid': 'mm_59461769_1953900113_110820900128', 'name': '券小九网站42'},
    {'pid': 'mm_59461769_1953900113_110814100262', 'name': '券小九网站43'},
    {'pid': 'mm_59461769_1953900113_110813000298', 'name': '券小九网站44'},
    {'pid': 'mm_59461769_1953900113_110814250253', 'name': '券小九网站45'},
    {'pid': 'mm_59461769_1953900113_110820200178', 'name': '券小九网站46'},
    {'pid': 'mm_59461769_1953900113_110814050259', 'name': '券小九网站47'},
    {'pid': 'mm_59461769_1953900113_110817450216', 'name': '券小九网站48'},
    {'pid': 'mm_59461769_1953900113_110818250184', 'name': '券小九网站49'},
    {'pid': 'mm_59461769_1953900113_110819600177', 'name': '券小九网站50'},
    {'pid': 'mm_59461769_1953900113_110814850242', 'name': '券小九网站51'},
    {'pid': 'mm_59461769_1953900113_110821000102', 'name': '券小九网站52'},
    {'pid': 'mm_59461769_1953900113_110815800199', 'name': '券小九网站53'},
    {'pid': 'mm_59461769_1953900113_110820700144', 'name': '券小九网站54'},
    {'pid': 'mm_59461769_1953900113_110820200179', 'name': '券小九网站55'},
    {'pid': 'mm_59461769_1953900113_110814400252', 'name': '券小九网站56'},
    {'pid': 'mm_59461769_1953900113_110819000177', 'name': '券小九网站57'},
    {'pid': 'mm_59461769_1953900113_110818950201', 'name': '券小九网站58'},
    {'pid': 'mm_59461769_1953900113_110816350217', 'name': '券小九网站59'},
    {'pid': 'mm_59461769_1953900113_110817650208', 'name': '券小九网站60'},
    {'pid': 'mm_59461769_1953900113_110816800208', 'name': '券小九网站61'},
    {'pid': 'mm_59461769_1953900113_110818700181', 'name': '券小九网站62'},
    {'pid': 'mm_59461769_1953900113_110818500172', 'name': '券小九网站63'},
    {'pid': 'mm_59461769_1953900113_110816550232', 'name': '券小九网站64'},
    {'pid': 'mm_59461769_1953900113_110814800273', 'name': '券小九网站66'},
    {'pid': 'mm_59461769_1953900113_110819900150', 'name': '券小九网站67'},
    {'pid': 'mm_59461769_1953900113_110820450154', 'name': '券小九网站68'},
    {'pid': 'mm_59461769_1953900113_110819250183', 'name': '券小九网站69'},
    {'pid': 'mm_59461769_1953900113_110815550237', 'name': '券小九网站70'},
    {'pid': 'mm_59461769_1953900113_110819200161', 'name': '券小九网站71'},
    {'pid': 'mm_59461769_1953900113_110816250217', 'name': '券小九网站72'},
    {'pid': 'mm_59461769_1953900113_110818900198', 'name': '券小九网站73'},
    {'pid': 'mm_59461769_1953900113_110815800202', 'name': '券小九网站74'},
    {'pid': 'mm_59461769_1953900113_110820400154', 'name': '券小九网站75'},
    {'pid': 'mm_59461769_1953900113_110814400253', 'name': '券小九网站76'},
    {'pid': 'mm_59461769_1953900113_110814750254', 'name': '券小九网站77'},
    {'pid': 'mm_59461769_1953900113_110819300163', 'name': '券小九网站78'},
    {'pid': 'mm_59461769_1953900113_110819800176', 'name': '券小九网站79'},
    {'pid': 'mm_59461769_1953900113_110814500234', 'name': '券小九网站80'},
    {'pid': 'mm_59461769_1953900113_110819000178', 'name': '券小九网站81'},
    {'pid': 'mm_59461769_1953900113_110818700182', 'name': '券小九网站82'},
    {'pid': 'mm_59461769_1953900113_110818700183', 'name': '券小九网站83'},
    {'pid': 'mm_59461769_1953900113_110816300225', 'name': '券小九网站84'},
    {'pid': 'mm_59461769_1953900113_110819200164', 'name': '券小九网站85'},
    {'pid': 'mm_59461769_1953900113_110814300272', 'name': '券小九网站86'},
    {'pid': 'mm_59461769_1953900113_110813300297', 'name': '券小九网站87'},
    {'pid': 'mm_59461769_1953900113_110815600209', 'name': '券小九网站88'},
    {'pid': 'mm_59461769_1953900113_110820900132', 'name': '券小九网站89'},
    {'pid': 'mm_59461769_1953900113_110813250270', 'name': '券小九网站90'},
    {'pid': 'mm_59461769_1953900113_110814300273', 'name': '券小九网站91'},
    {'pid': 'mm_59461769_1953900113_110818750202', 'name': '券小九网站92'},
    {'pid': 'mm_59461769_1953900113_110816200185', 'name': '券小九网站93'},
    {'pid': 'mm_59461769_1953900113_110816850201', 'name': '券小九网站94'},
    {'pid': 'mm_59461769_1953900113_110819200167', 'name': '券小九网站95'},
    {'pid': 'mm_59461769_1953900113_110820650147', 'name': '券小九网站96'},
    {'pid': 'mm_59461769_1953900113_110814350231', 'name': '券小九网站97'},
    {'pid': 'mm_59461769_1953900113_110814400254', 'name': '券小九网站98'},
    {'pid': 'mm_59461769_1953900113_110814550272', 'name': '券小九网站99'},
    {'pid': 'mm_59461769_1953900113_110813300298', 'name': '券小九网站100'},
    {'pid': 'mm_59461769_1953900113_110817350200', 'name': '券小九网站101'},
    {'pid': 'mm_59461769_1953900113_110814250255', 'name': '券小九网站102'},
    {'pid': 'mm_59461769_1953900113_110820600136', 'name': '券小九网站103'},
    {'pid': 'mm_59461769_1953900113_110817600187', 'name': '券小九网站104'},
    {'pid': 'mm_59461769_1953900113_110815400252', 'name': '券小九网站105'},
    {'pid': 'mm_59461769_1953900113_110814150253', 'name': '券小九网站106'},
    {'pid': 'mm_59461769_1953900113_110813650248', 'name': '券小九网站107'},
    {'pid': 'mm_59461769_1953900113_110819250186', 'name': '券小九网站108'},
    {'pid': 'mm_59461769_1953900113_110814450224', 'name': '券小九网站109'},
    {'pid': 'mm_59461769_1953900113_110818800184', 'name': '券小九网站110'},
    {'pid': 'mm_59461769_1953900113_110818200205', 'name': '券小九网站111'},
    {'pid': 'mm_59461769_1953900113_110817100220', 'name': '券小九网站112'},
    {'pid': 'mm_59461769_1953900113_110818050176', 'name': '券小九网站113'},
    {'pid': 'mm_59461769_1953900113_110815300260', 'name': '券小九网站114'},
    {'pid': 'mm_59461769_1953900113_110817850195', 'name': '券小九网站115'},
    {'pid': 'mm_59461769_1953900113_110820400156', 'name': '券小九网站116'},
    {'pid': 'mm_59461769_1953900113_110812700336', 'name': '券小九网站117'},
    {'pid': 'mm_59461769_1953900113_110814450225', 'name': '券小九网站118'},
    {'pid': 'mm_59461769_1953900113_110818800185', 'name': '券小九网站119'},
    {'pid': 'mm_59461769_1953900113_110820350157', 'name': '券小九网站120'},
    {'pid': 'mm_59461769_1953900113_110818200206', 'name': '券小九网站121'},
    {'pid': 'mm_59461769_1953900113_110815600213', 'name': '券小九网站122'},
    {'pid': 'mm_59461769_1953900113_110820700145', 'name': '券小九网站123'},
    {'pid': 'mm_59461769_1953900113_110819200168', 'name': '券小九网站124'},
    {'pid': 'mm_59461769_1953900113_110817800195', 'name': '券小九网站125'},
    {'pid': 'mm_59461769_1953900113_110814500238', 'name': '券小九网站126'},
    {'pid': 'mm_59461769_1953900113_110813050288', 'name': '券小九网站127'},
    {'pid': 'mm_59461769_1953900113_110816300226', 'name': '券小九网站128'},
    {'pid': 'mm_59461769_1953900113_110815650238', 'name': '券小九网站129'},
    {'pid': 'mm_59461769_1953900113_110820650150', 'name': '券小九网站130'},
    {'pid': 'mm_59461769_1953900113_110818100164', 'name': '券小九网站131'},
    {'pid': 'mm_59461769_1953900113_110813900257', 'name': '券小九网站132'},
    {'pid': 'mm_59461769_1953900113_110819900153', 'name': '券小九网站133'},
    {'pid': 'mm_59461769_1953900113_110818750207', 'name': '券小九网站134'},
    {'pid': 'mm_59461769_1953900113_110819400181', 'name': '券小九网站135'},
    {'pid': 'mm_59461769_1953900113_110816400232', 'name': '券小九网站136'},
    {'pid': 'mm_59461769_1953900113_110816200189', 'name': '券小九网站137'},
    {'pid': 'mm_59461769_1953900113_110815000249', 'name': '券小九网站138'},
    {'pid': 'mm_59461769_1953900113_110820500127', 'name': '券小九网站139'},
    {'pid': 'mm_59461769_1953900113_110817600190', 'name': '券小九网站140'},
    {'pid': 'mm_59461769_1953900113_110817300181', 'name': '券小九网站141'},
    {'pid': 'mm_59461769_1953900113_110815750232', 'name': '券小九网站142'},
    {'pid': 'mm_59461769_1953900113_110813200235', 'name': '券小九网站143'},
    {'pid': 'mm_59461769_1953900113_110818600186', 'name': '券小九网站144'},
    {'pid': 'mm_59461769_1953900113_110816250219', 'name': '券小九网站145'},
    {'pid': 'mm_59461769_1953900113_110820200181', 'name': '券小九网站146'},
    {'pid': 'mm_59461769_1953900113_110813450294', 'name': '券小九网站147'},
    {'pid': 'mm_59461769_1953900113_110814250257', 'name': '券小九网站148'},
    {'pid': 'mm_59461769_1953900113_110817000202', 'name': '券小九网站149'},
    {'pid': 'mm_59461769_1953900113_110813000300', 'name': '券小九网站150'},
    {'pid': 'mm_59461769_1953900113_110817750208', 'name': '券小九网站151'},
    {'pid': 'mm_59461769_1953900113_110814850243', 'name': '券小九网站152'},
    {'pid': 'mm_59461769_1953900113_110817750209', 'name': '券小九网站153'},
    {'pid': 'mm_59461769_1953900113_110812800312', 'name': '券小九网站154'},
    {'pid': 'mm_59461769_1953900113_110817600191', 'name': '券小九网站155'},
    {'pid': 'mm_59461769_1953900113_110820550153', 'name': '券小九网站156'},
    {'pid': 'mm_59461769_1953900113_110818150198', 'name': '券小九网站157'},
    {'pid': 'mm_59461769_1953900113_110820700150', 'name': '券小九网站158'},
    {'pid': 'mm_59461769_1953900113_110816650225', 'name': '券小九网站159'},
    {'pid': 'mm_59461769_1953900113_110820700151', 'name': '券小九网站160'},
    {'pid': 'mm_59461769_1953900113_110813300300', 'name': '券小九网站161'},
    {'pid': 'mm_59461769_1953900113_110815200248', 'name': '券小九网站162'},
    {'pid': 'mm_59461769_1953900113_110814550276', 'name': '券小九网站163'},
    {'pid': 'mm_59461769_1953900113_110817750210', 'name': '券小九网站164'},
    {'pid': 'mm_59461769_1953900113_110820200183', 'name': '券小九网站165'},
    {'pid': 'mm_59461769_1953900113_110815550239', 'name': '券小九网站166'},
    {'pid': 'mm_59461769_1953900113_110815750233', 'name': '券小九网站167'},
    {'pid': 'mm_59461769_1953900113_110816800214', 'name': '券小九网站168'},
    {'pid': 'mm_59461769_1953900113_110813250273', 'name': '券小九网站169'},
    {'pid': 'mm_59461769_1953900113_110818300195', 'name': '券小九网站170'},
    {'pid': 'mm_59461769_1953900113_110814850245', 'name': '券小九网站171'},
    {'pid': 'mm_59461769_1953900113_110817200217', 'name': '券小九网站172'},
    {'pid': 'mm_59461769_1953900113_110815200251', 'name': '券小九网站173'},
    {'pid': 'mm_59461769_1953900113_110818050179', 'name': '券小九网站174'},
    {'pid': 'mm_59461769_1953900113_110817800197', 'name': '券小九网站175'},
    {'pid': 'mm_59461769_1953900113_110814600256', 'name': '券小九网站176'},
    {'pid': 'mm_59461769_1953900113_110814150256', 'name': '券小九网站177'},
    {'pid': 'mm_59461769_1953900113_110820750125', 'name': '券小九网站178'},
    {'pid': 'mm_59461769_1953900113_110818450202', 'name': '券小九网站179'},
    {'pid': 'mm_59461769_1953900113_110814200274', 'name': '券小九网站180'},
    {'pid': 'mm_59461769_1953900113_110819650151', 'name': '券小九网站181'},
    {'pid': 'mm_59461769_1953900113_110815600214', 'name': '券小九网站182'},
    {'pid': 'mm_59461769_1953900113_110817300182', 'name': '券小九网站183'},
    {'pid': 'mm_59461769_1953900113_110817000204', 'name': '券小九网站184'},
    {'pid': 'mm_59461769_1953900113_110817150194', 'name': '券小九网站185'},
    {'pid': 'mm_59461769_1953900113_110816850204', 'name': '券小九网站186'},
    {'pid': 'mm_59461769_1953900113_110815300264', 'name': '券小九网站187'},
    {'pid': 'mm_59461769_1953900113_110819750187', 'name': '券小九网站188'},
    {'pid': 'mm_59461769_1953900113_110815000251', 'name': '券小九网站189'},
    {'pid': 'mm_59461769_1953900113_110820750127', 'name': '券小九网站190'},
    {'pid': 'mm_59461769_1953900113_110817250190', 'name': '券小九网站191'},
    {'pid': 'mm_59461769_1953900113_110814400256', 'name': '券小九网站192'},
    {'pid': 'mm_59461769_1953900113_110816450207', 'name': '券小九网站193'},
    {'pid': 'mm_59461769_1953900113_110815800205', 'name': '券小九网站194'},
    {'pid': 'mm_59461769_1953900113_110819750188', 'name': '券小九网站195'},
    {'pid': 'mm_59461769_1953900113_110814800277', 'name': '券小九网站196'},
    {'pid': 'mm_59461769_1953900113_110817800201', 'name': '券小九网站197'},
    {'pid': 'mm_59461769_1953900113_110814400257', 'name': '券小九网站198'},
    {'pid': 'mm_59461769_1953900113_110816850256', 'name': '券小九网站199'}]

